import logging
import time

from src.common.mem_data import MemData

LOG = logging.getLogger()


class CloseBrowser(object):
    def __init__(self):
        self.browser = MemData.browser
        self.pages = MemData.pages

    async def close_pages(self):
        for page in self.pages:
            await page.close()
        if MemData.page:
            await MemData.page.close()

    async def close_browser(self):
        await self.browser.close()
        LOG.info('browser closed')

    async def run(self):
        time.sleep(3)
        await self.close_pages()
        await self.close_browser()
